<template>
	<yd-layout id='goodsDetail' class=''>
		<div class="header">
			<div class="header_banner">
				<van-swipe :autoplay="3000" indicator-color="white">
					<van-swipe-item v-for='item in headerList'>
						<img src="" @click="goBannerView(item)" :src="item" alt="" />
					</van-swipe-item>
				</van-swipe>
			</div>
			<div class="header_bottm">
				<div class="header_money">
					<div class="header_money_c">￥{{dataObj.price}}</div><span>￥{{dataObj.org_price}}</span>
				</div>
				<div class="header_title">
					<!--<img class="img" v-if="dataObj.free_post==1" src="../../../assets/goodsDetail_1.png" alt="" />-->
					<span class="header_title_label c_size_34_48">{{dataObj.name}}</span>
				</div>
				<div class="header_label">已售{{dataObj.sell_number}}</div>
			</div>
		</div>
		<div class="content">
			<div class="title c_size_34_48">商品详情</div>
			<div class="c_v_html"  v-html="dataObj.detail"></div>
		</div>
		<div class="bottom_btn" @click="showPop=true" slot='bottom'>立即购买</div>
		<yd-popup v-model="showPop" position="bottom" class='pop' height="19.27%">
			<div class="pop_top c_size_34_48">
				<div class="pop_top_left">请选择购买数量：</div>
				<div class="pop_top_right">
					<img  @click="jian"  src="../../../assets/goodsDetail_3.png" alt="" />
					<!--oninput="if(value.length>18)value=value.slice(0,18)"-->
					<input 
						class="pop_input" 
						pattern="\d*"  
						v-model.number.trim="inputNum" 
						maxlength="4"
						@blur="blurNumInput(inputNum)"
						@input='changeNumInput(inputNum)'
						oninput="if(value.length>4)value=value.slice(0,4)"
					   type="number" />
					<img @click="add" src="../../../assets/goodsDetail_2.png" alt="" />
				</div>
			</div>
			<div slot='bottom' @click="goGoodsOrder" class="pop_bottom">立即购买</div>
        </yd-popup>
	</yd-layout>
</template>

<script>
	import { Swipe, SwipeItem } from 'vant';
	import {Popup} from 'vue-ydui/dist/lib.rem/popup';
	import mixinInputReg from '../../../mixin/mixinInputReg.js';
	export default{
		mixins:[mixinInputReg],
		components:{
			[Swipe.name]: Swipe,
			[SwipeItem.name]: SwipeItem,
			[Popup.name]: Popup,

		},
		data(){
			return {
				cs:'<strong>123</strong>',
				showPop:false,
				inputNum:1,
				dataObj:{},
				headerList:[],
			}
		},
		created() {
		},
		watch: {
			
		},
		computed: {
			
		},
		mounted(){
			document.title='商品详情'
			this.getGoodsDetail()
		},
		methods:{
			goBannerView(){
				
			},
			getGoodsDetail(){
				this.$root.ajax({
					name: 'shop/goods',
					type:'get',
					params: {
						id:1
					}
				}).then((d) => {
					d.data.price = this.setMoneyZero(d.data,'price')
					d.data.org_price = this.setMoneyZero(d.data,'org_price')
					this.dataObj=Object.assign({},this.dataObj,d.data)
					this.headerList = d.data.albums;
					
					//分享
					if(this.$root.isWeiXin()){
						//分享
						let query = '';
						if(this.$root.config.channel){
						 	query = `params=channelDY2FGoldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${this.dataObj.id}`
						}else{
						 	query = `params=oldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${this.dataObj.id}`
						}
						this.$root.wxShare({
							d:{title:this.dataObj.name,title_img:this.dataObj.img},//分享对象，题目等{title:'',title-img:''}
							query: query,//参数
							desc:`限时促销，速速抢购~`//分享详情
						})
					}
					
				})
			},
			//处理金钱的0
			setMoneyZero(obj,str){
				if(obj[str]||obj[str]===0){
					if((obj[str]+'').indexOf('.')>=0){
						return obj[str]=obj[str].toFixed(1)
					}else{
						console.log(obj[str])
						return obj[str] = obj[str] + '.0'
					}
				}
			},
			goGoodsOrder(){
				this.$root.ajax({
					name: 'shop/order/create',
					params: {
						goods_id:1,
						number:this.inputNum
					}
				}).then((d) => {
					this.$router.push({
						name:'bd_goodsOrder',
						query:{
							id:d.data.id,
							free_post:this.dataObj.free_post
						}
					})
				})
				
			},
			add(){
				this.inputNum = parseFloat(this.inputNum)
				console.log(this.inputNum)
				if(this.inputNum>=9999){
					this.$dialog.toast({
	                    mes: '数量不能大于9999',
	                    timeout: 1500,
	                });
					this.inputNum=9999
				}else{
					this.inputNum = this.inputNum + 1
				}
			},
			jian(){
				if(this.inputNum>1){
					this.inputNum = this.inputNum - 1
				}else{
					this.$dialog.toast({
	                    mes: '数量至少为1',
	                    timeout: 1500,
	                });
				}
				
			},
		}
	}
</script>

<style lang="scss">
	@import './goodsDetail.scss';
</style>